package com.neusoft.resturant.controller;

import com.neusoft.resturant.entity.Student;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/student")
public class StudentController {

    //http://localhost:8080/api/student/detail?sno=202200018&name=张三&sex=男
    @GetMapping("/detail")
    public Student getDetail(HttpServletRequest request){


        String sno = request.getParameter( "sno");
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        System.out.println("学生学号: "+sno);
        System.out.println("学生姓名: "+name);

        Student student = new Student();
        student.setName(name);
        student.setSno(sno);
        student.setSex(sex);
        return student;
    }

    //http://localhost:8080/api/student/detail1?sno=202200018&name=张三&sex=男
    @GetMapping("/detail1")
    public Student Detail(String sno,String name,String sex){

        System.out.println("学生学号: "+sno);
        System.out.println("学生姓名: "+name);

        Student student = new Student();
        student.setName(name);
        student.setSno(sno);
        student.setSex(sex);
        return student;
    }

    //http://localhost:8080/api/student/detail2?sno=202200018&name=张三&sex=男
    @GetMapping("/detail2")
    public Student Detail2(Student student){

        System.out.println("detail2");

        return student;
    }
    //http://localhost:8080/api/student/detail3
    @RequestMapping(value = "/detail3", method = RequestMethod.GET)
    public void getUserName(@RequestParam(value = "name",
            required = false, defaultValue =  "lisi") String stuName){
        System.out.println("stuName=" + stuName);
    }
}
